//
//  LoginViewController.m
//  LTChat
//
//  Created by apple on 4/8/14.
//  Copyright (c) 2014 fantasy. All rights reserved.
//

#import "LoginViewController.h"
#import "LTFriendsViewController.h"
#import "AppDelegate.h"
#import "XMPPConfig.h"

@interface LoginViewController ()

@end

@implementation LoginViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
//    self.usernameTextField.text = [[NSUserDefaults standardUserDefaults] stringForKey:XMPPUSERID];
//    self.passwordTextField.text = [[NSUserDefaults standardUserDefaults] stringForKey:XMPPPASS];
    [[[self appdelegate] xmppChatManager] loginWithAnonymous];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)login:(id)sender
{
    
    
    [[[self appdelegate] xmppChatManager] loginWithUsername:self.usernameTextField.text password:self.passwordTextField.text];
//    [[UIApplication sharedApplication] keyWindow].rootViewController = [[UINavigationController alloc] initWithRootViewController:[[LTViewController alloc] init]];
    
    UINavigationController *friends = [[UINavigationController alloc] initWithRootViewController:[[LTFriendsViewController alloc] init]];
    UITabBarController *tbCtrl = [[UITabBarController alloc] init];
    [tbCtrl setViewControllers:[NSArray arrayWithObjects:friends, nil]];
    [tbCtrl setSelectedIndex:0];
    [[UIApplication sharedApplication] keyWindow].rootViewController = tbCtrl;
}

-(AppDelegate *)appdelegate
{
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    return app;
}

-(IBAction)registerAccount:(id)reg
{
    [[[self appdelegate] xmppChatManager] registerWithUsername:self.usernameTextField.text password:self.passwordTextField.text];
}

@end
